const request = require('../utils/request')

Page({
  data: {
    banners: [
      { id: 1, image: '/assets/images/banner1.jpg' },
      { id: 2, image: '/assets/images/banner2.jpg' }
    ],
    hotDishes: []
  },

  onLoad() {
    this.loadHotDishes()
  },

  async loadHotDishes() {
    try {
        const res = await request('/api/menu/dishes')
        this.setData({
            hotDishes: res.data.slice(0, 4),
        })
    } catch (error) {
        console.error('获取热门商品失败:', error)
        wx.showToast({
            title: '获取热门商品失败',
            icon: 'none'
        })
    }
  },

  // 跳转到商品详情页面
  navigateToDetail(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/goods-detail/goods-detail?id=${id}`
    });
  }
})